package main

import (
	"fmt"
	"sync"
	"time"
)

func main() {
	wg := sync.WaitGroup{}
	now := time.Now()
	c := make(chan interface{})
	//defer close(c)
	for i := 0; i < 5; i++ {

		wg.Add(1)
		go func(parm int) {
			defer wg.Done()
			c <- job(parm)
		}(i)

	}

	//go func() {
	//for {
	//
	//fmt.Println("收集到的结果：", <-c)
	//}
	//}()

	//wg.Wait()
	go func() {
		defer close(c)
		wg.Wait()
	}()

	for e := range c {
		fmt.Printf("收集到的结果 = %#v\n", e)
	}
	fmt.Println(time.Since(now))

}

func job(parm int) int {
	time.Sleep(time.Second)
	return parm
}
